<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;

class PlinkController extends AdminController {


    public function index(){

        $plink = D('Plink');
        $infos = $this->lists($plink);

        $this->assign('infos',$infos);
        $this->display();
    }
    public function add(){
        $id = $_GET['id'];
        if(!empty($id)){
            $info = D("Plink")->find($id);
            $this->assign("info",$info);
        }

        $this->display();
    }

    public  function save(){
//        dump($_POST);
        $data = I();
        if(!empty($data['id'])){
            $data['utime'] = time();
        }else{
            $data['ctime'] = time();
            $data['utime'] = time();
        }

        $res = D("Plink")->update($data);
        if(!$res){
            $this->error(D('Plink')->getError());
        }else{
            if($res['id']){
                $this->success('更新成功',U('index'));
            }else{
                $this->success('添加成功',U('index'));
            }
        }
    }

    public function del(){
        $id = $_GET['id'];
        $plink = D("Plink");
        if (!empty($id)) {
//            $info = $plink->select($id);
        } else {
            $id = array_unique((array)I('id', 0));
            $id = is_array($id) ? implode(',', $id) : $id;
        }

        $res = $plink->delete($id);
//        dump($res);
        if ($res) {
            $this->success('删除成功', U('index'));
        } else {
            $this->success('删除失败', U('index'));
        }

//        $this->display();
    }

}
